package com.eboss2.sbs.adapter;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.ActivityOrderDetail;
import com.eboss2.sbs.enums.EnumConsts;
import com.eboss2.sbs.interfaces.OrderManagerCallBackListener;
import com.eboss2.sbs.interfaces.RefundCallbackListener;
import com.eboss2.sbs.model.OrderListInfo;
import com.eboss2.sbs.model.OrderManagerInfo;
import com.eboss2.sbs.weight.DialogUtils;
import com.eboss2.sbs.weight.MyCustomDialog;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;
import com.tool.utils.view.MyListView;

import java.util.ArrayList;
import java.util.List;

public class OrderManagerAdapter extends BaseAdapter {

	private Context context;
	private List<OrderManagerInfo> datas;
	private LayoutInflater inflater;
	private ViewHolder holder = null;
	private OrderManagerCallBackListener listener;

	public OrderManagerAdapter(Context context, List<OrderManagerInfo> datas, OrderManagerCallBackListener listener) {
		this.context = context;
		this.datas = datas;
		this.listener = listener;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if(datas!=null&&datas.size()>0)return datas.size();
		else return 0;
	}

	@Override
	public OrderManagerInfo getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		


		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_order_notice, null);
			
			holder.tv_order_status = (TextView) convertView.findViewById(R.id.tv_order_status);
			holder.tv_order_no = (TextView) convertView.findViewById(R.id.tv_order_no);
			holder.tv_user_name = (TextView) convertView.findViewById(R.id.tv_user_name);
			holder.tv_order_num = (TextView) convertView.findViewById(R.id.tv_order_num);
			holder.tv_ems_amt = (TextView) convertView.findViewById(R.id.tv_ems_amt);
			holder.tv_order_amt = (TextView) convertView.findViewById(R.id.tv_order_amt);
			holder.tv_recipients = (TextView) convertView.findViewById(R.id.tv_recipients);
			holder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
			holder.tv_address_content = (TextView) convertView.findViewById(R.id.tv_address_content);
			holder.tv_btn_1 = (SuperButton) convertView.findViewById(R.id.tv_btn_1);
			holder.tv_btn_2 = (SuperButton) convertView.findViewById(R.id.tv_btn_2);
			holder.tv_btn_3 = (SuperButton) convertView.findViewById(R.id.tv_btn_3);
			holder.tv_btn_4 = (SuperButton) convertView.findViewById(R.id.tv_btn_4);
			holder.tv_ems_name = (TextView) convertView.findViewById(R.id.tv_ems_name);
			holder.tv_ems_no = (TextView) convertView.findViewById(R.id.tv_ems_no);
			holder.tv_ems_content = (TextView) convertView.findViewById(R.id.tv_ems_content);
			holder.tv_ems_time = (TextView) convertView.findViewById(R.id.tv_ems_time);
			holder.img_qi = (ImageView) convertView.findViewById(R.id.img_qi);
			holder.ll_spec = (LinearLayout) convertView.findViewById(R.id.ll_spec);
			holder.ll_button = (LinearLayout) convertView.findViewById(R.id.ll_button);
			holder.ll_address = (LinearLayout) convertView.findViewById(R.id.ll_address);
			holder.ll_ems = (LinearLayout) convertView.findViewById(R.id.ll_ems);
			holder.listview_spec = (MyListView) convertView.findViewById(R.id.listview_spec);
			holder.tv_more = (TextView) convertView.findViewById(R.id.tv_more);



			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}


		//初始化按钮(隐藏)
		holder.ll_button.setVisibility(View.GONE);
		holder.ll_ems.setVisibility(View.GONE);
		holder.ll_address.setVisibility(View.VISIBLE);



		final OrderManagerInfo data = datas.get(position);

		//订单号
		holder.tv_order_no.setText(StringUtils.isBlank(data.getOrderNo()) ? "" : "订单号: "+data.getOrderNo());


		//订单状态
		if (EnumConsts.OrderStatus.ORDER_STATUS_YFH.getState() == data.getStatus()){ //已发货
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_YFH.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_YFH.getColor()));
//			holder.ll_ems.setVisibility(View.VISIBLE);

			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));



			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = data.getPhone(); //holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}

			//快递公司
			holder.tv_ems_name.setText(StringUtils.isBlank(data.getExpressName()) ? "" : data.getExpressName());
			holder.tv_ems_no.setText(StringUtils.isBlank(data.getExpressNo()) ? "" : data.getExpressNo());
//			holder.tv_ems_content.setText(data.getEmsContent());
//			holder.tv_ems_time.setText(data.getEmsTime());

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DFK.getState() == data.getStatus()){ // 待付款

			//设置状态UI
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_DFK.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_DFK.getColor()));
			holder.ll_button.setVisibility(View.VISIBLE);

			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));

			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}

			holder.tv_btn_1.setVisibility(View.VISIBLE);
			holder.tv_btn_1.setText("关闭订单");
			holder.tv_btn_1.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (listener != null){
						listener.setCancalOrder(data.getId());
					}
				}
			});
			holder.tv_btn_2.setVisibility(View.GONE);
			holder.tv_btn_2.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText(data.getOrderNo());
					ToastUtils.CustomShow(context, "复制成功");
				}
			});
			holder.tv_btn_3.setVisibility(View.VISIBLE);
			holder.tv_btn_3.setText("修改价格");
			holder.tv_btn_3.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (listener != null){
						listener.EditPrice(data.getId(), data.getGoodAmount(), data.getFreightCharge());
					}
				}
			});

			holder.tv_btn_4.setVisibility(View.GONE);

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DFH.getState() == data.getStatus()){ //待发货
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_DFH.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_DFH.getColor()));
			holder.ll_button.setVisibility(View.VISIBLE);
			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));

			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}


			holder.tv_btn_1.setVisibility(View.VISIBLE);
			holder.tv_btn_1.setText("商家自送");
			holder.tv_btn_1.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (listener != null){
						listener.setZt(data.getId());
					}
				}
			});
			holder.tv_btn_2.setVisibility(View.GONE);
			holder.tv_btn_2.setOnClickListener(new View.OnClickListener() { //复制订单
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText(data.getOrderNo());
					ToastUtils.CustomShow(context, "复制成功");
				}
			});
			holder.tv_btn_3.setVisibility(View.VISIBLE);
			holder.tv_btn_3.setText("发货");
			holder.tv_btn_3.setOnClickListener(new View.OnClickListener() { //发货
				@Override
				public void onClick(View view) {
					if (listener != null){
						listener.setFh(data.getId(),"", "", "", null);
					}
				}
			});

			holder.tv_btn_4.setVisibility(View.GONE);

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DPJ.getState() == data.getStatus()){ //待评价
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_DPJ.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_DPJ.getColor()));
			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));

			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_TKZ.getState() == data.getStatus()){ //退款中
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_TKZ.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_TKZ.getColor()));
			holder.ll_button.setVisibility(View.VISIBLE);
			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));

			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}
			holder.tv_btn_1.setVisibility(View.GONE);
			holder.tv_btn_2.setVisibility(View.VISIBLE);
			holder.tv_btn_2.setText("确认退款");
			holder.tv_btn_2.setOnClickListener(new View.OnClickListener() { //复制订单
				@Override
				public void onClick(View view) {
					String amt = StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge());
//					StringBuilder message = new StringBuilder();
//					message.append("是否确认退款，确认后，购物款项");
//					message.append(amt);
//					message.append("将直接退还给消费者.");
//					MyDialog.Builder builder = new MyDialog.Builder(context);
//					builder.setTitle("确认退款");
//					builder.setMessage(message.toString());
//					builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//						public void onClick(DialogInterface dialog, int which) {
//							if (listener != null){
//								listener.RefundSure(data.getId(), dialog, data.getGoodAmount());
//							}
//						}
//					});
//					builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//						@Override
//						public void onClick(DialogInterface dialog, int arg1) {
//							dialog.dismiss();
//						}
//					});
//					builder.create().show();
					DialogUtils.showDialogRefund(context, amt, new RefundCallbackListener() {
						@Override
						public void refundCallback(String amt, String content, MyCustomDialog dialog) {
							if (listener != null){
								listener.RefundSure(data.getId(), dialog, StringUtils.changeY2F(amt), content);
							}
						}
					});
				}
			});
			holder.tv_btn_3.setVisibility(View.GONE);
			holder.tv_btn_4.setVisibility(View.VISIBLE);
			holder.tv_btn_4.setText("拒绝退款");
			holder.tv_btn_4.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					DialogUtils.showRefundDialog(context, "拒绝退款", "拒绝理由：", "",  new DialogUtils.Callback() {
						@Override
						public void getData(String str, MyCustomDialog dialog) {
							if (listener != null){
								listener.RefundRefused(data.getId(), dialog, str);
							}
						}
					});
				}
			});

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_YWC.getState() == data.getStatus()){ //已完成
			holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_YWC.getName());
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_YWC.getColor()));

			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//隐藏收货人布局
			holder.ll_address.setVisibility(View.GONE);


		}else if (EnumConsts.OrderStatus.ORDER_STATUS_YTK.getState() == data.getStatus() || EnumConsts.OrderStatus.ORDER_STATUS_TKJJ.getState() == data.getStatus()){ //已退款
			if (EnumConsts.OrderStatus.ORDER_STATUS_YTK.getState() == data.getStatus()) {
				holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_YTK.getName());
				holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_YTK.getColor()));
			}else {
				holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_TKJJ.getName());
				holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_TKJJ.getColor()));
			}


			//用户名
			holder.tv_user_name.setText(StringUtils.isBlank(data.getMemberName()) ? "" : data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//隐藏收货人布局
			holder.ll_address.setVisibility(View.GONE);

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_YGB.getState() == data.getStatus() ||
				EnumConsts.OrderStatus.ORDER_STATUS_YQX.getState() == data.getStatus()
				){ //已关闭
			if (EnumConsts.OrderStatus.ORDER_STATUS_YGB.getState() == data.getStatus()) {
				holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_YGB.getName());
			}else if (EnumConsts.OrderStatus.ORDER_STATUS_YQX.getState() == data.getStatus()){
				holder.tv_order_status.setText(EnumConsts.OrderStatus.ORDER_STATUS_YQX.getName());
			}
			holder.tv_order_status.setTextColor(context.getResources().getColor(EnumConsts.OrderStatus.ORDER_STATUS_YGB.getColor()));
			//用户名
			holder.tv_user_name.setText(data.getMemberName());
			//数量
			holder.tv_order_num.setText("共"+data.getGoodNum()+"件商品");
			//含快递费
			holder.tv_ems_amt.setText("(含快递:"+StringUtils.formatIntMoney(data.getFreightCharge())+"元): ");
			//实付金额
			holder.tv_order_amt.setText("￥"+StringUtils.formatIntMoney(data.getGoodAmount()-data.getBonusCover()-data.getCouponCover() + data.getFreightCharge()));
			//收件人
			holder.tv_recipients.setText(StringUtils.isBlank(data.getCustomerName()) ? "" : data.getCustomerName());
			//电话
			holder.tv_phone.setText(StringUtils.isBlank(data.getPhone()) ? "" : data.getPhone());
			//地址
			holder.tv_address_content.setText((StringUtils.isBlank(data.getCity()) ? "" : data.getCity()) + (StringUtils.isBlank(data.getArea()) ? "" : data.getArea()));

			//是否有电话
			if (!StringUtils.isEmpty(data.getPhone())){
				holder.tv_phone.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View view) {
//						final String phone = holder.tv_phone.getText().toString().trim();
						DialogUtils.alert("拨打 " + data.getPhone(), null, context, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getPhone()));
								// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								context.startActivity(intent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();

							}
						});

					}
				});
			}
		}



		//商品列表
		if(data.getOrderGoodItemList() != null && data.getOrderGoodItemList().size() > 0){

			if (data.getOrderGoodItemList().size() > 2) {
				List<OrderListInfo> serviceGoodsListInfos = new ArrayList<>();
				serviceGoodsListInfos.add(data.getOrderGoodItemList().get(0));
				serviceGoodsListInfos.add(data.getOrderGoodItemList().get(1));
				holder.listview_spec.setAdapter(new OrderListAdapter(context, serviceGoodsListInfos));
				holder.tv_more.setVisibility(View.VISIBLE);
			}else{
				holder.listview_spec.setAdapter(new OrderListAdapter(context, data.getOrderGoodItemList()));
				holder.tv_more.setVisibility(View.GONE);
			}

			holder.listview_spec.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
					context.startActivity(new Intent(context, ActivityOrderDetail.class).putExtra("status", data.getStatus()).putExtra("orderId", data.getId()));
				}
			});

		}else{
			holder.listview_spec.setVisibility(View.GONE);
		}






		//是否有备注
		if (!StringUtils.isEmpty(data.getRemark())){
			holder.img_qi.setImageResource(R.mipmap.icon_qi2);
		}else{
			holder.img_qi.setImageResource(R.mipmap.icon_qi1);
		}
		holder.img_qi.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				ShowBackContent(context, data.getRemark(), data.getId());
			}
		});









		return convertView;
	}


	private void ShowBackContent(final Context mContext, String content, final Long id){

		DialogUtils.showBackContentDialog(mContext, "添加备注", "备注内容", content,  new DialogUtils.Callback() {
			@Override
			public void getData(String data, MyCustomDialog dialog) {
				if (StringUtils.isEmpty(data)){
					holder.img_qi.setImageResource(R.mipmap.icon_qi1);
				}else{

					if (listener != null){
						listener.addBack(id, data, holder.img_qi, dialog);
					}
				}
			}
		});
	}




	public final class ViewHolder {
		private TextView tv_order_status;
		private TextView tv_order_no;
		private ImageView img_qi;
		private LinearLayout ll_spec;
		private MyListView listview_spec;
		private TextView tv_user_name;
		private TextView tv_order_num;
		private TextView tv_ems_amt;
		private TextView tv_order_amt;
		private TextView tv_recipients;
		private TextView tv_phone;
		private TextView tv_address_content;
		private LinearLayout ll_button;
		private LinearLayout ll_address;
		private LinearLayout ll_ems;
		private SuperButton tv_btn_1;
		private SuperButton tv_btn_2;
		private SuperButton tv_btn_3;
		private SuperButton tv_btn_4;
		private TextView tv_ems_name;
		private TextView tv_ems_no;
		private TextView tv_ems_content;
		private TextView tv_ems_time;
		private TextView tv_more;


	}

}
